package com.bkd.dreams.client.volunteer;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.jdo.annotations.Extension;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
import javax.jdo.annotations.Unique;

import com.bkd.dreams.client.event.VolunteerEvent;

@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "false")
public class Volunteer implements Serializable {

	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	@Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value = "true")
	private String key;
	
	@Persistent
	private String name;
	
	@Persistent
	private String phoneNumber;
	
	@Persistent
	private String email;
	
	@Persistent
	@Unique
	private String userId;
	
	@Persistent
	private boolean administrator;
	
	@Persistent
	private List<String> signedUpEvents;

	@Persistent
	private Date twinsTraining;
	
	@Persistent
	private Date vikingsTraining;
	
	@Persistent
	private Date twinsManagerTraining;
	
	@Persistent
	private Date vikingsManagerTraining;
	
	public Volunteer() {
	}
	
	public Volunteer(String name, String phoneNumber, String email, String userId, boolean administrator) {
		this.name = name;
		this.phoneNumber = phoneNumber;
		this.email = email;
		this.userId = userId;
		this.administrator = administrator;
	}

	public Volunteer(VolunteerDTO volunteer) {
		this.name = volunteer.getName();
		this.phoneNumber = volunteer.getPhoneNumber();
		this.email = volunteer.getEmail();
		this.userId = volunteer.getUserId();
		this.administrator = volunteer.isAdministrator();
		this.signedUpEvents = new ArrayList<String>();
		if(volunteer.getSignedUpEvents() != null) {
			this.signedUpEvents.addAll(volunteer.getSignedUpEvents());
		}
		this.twinsTraining = volunteer.getTwinsTraining();
		this.twinsManagerTraining = volunteer.getTwinsManagerTraining();
		this.vikingsTraining = volunteer.getVikingsTraining();
		this.vikingsManagerTraining = volunteer.getVikingsManagerTraining();
	}

	public String getKey() {
		return this.key;
	}
	
	public String getName() {
		return this.name;
	}
	
	public void setName(String name) {
		this.name = name;
	}
	
	public String getPhoneNumber() {
		return this.phoneNumber;
	}
	
	public void setPhoneNumber(String phoneNumber) {
		this.phoneNumber = phoneNumber;
	}
	
	public String getEmail() {
		return this.email;
	}
	
	public void setEmail(String email) {
		this.email = email;
	}
	
	public String getUserId() {
		return this.userId;
	}
	
	public void setUserId(String userId) {
		this.userId = userId;
	}
	
	public boolean isAdministrator() {
		return this.administrator;
	}
	
	public Date getTwinsTraining() {
		return this.twinsTraining;
	}
	
	public void setTwinsTraining(Date trainingDate) {
		this.twinsTraining = trainingDate;
	}
	
	public Date getVikingsTraining() {
		return this.vikingsTraining;
	}
	// 877-279-0017 claim # L31147891 need dispatch #
	public void setVikingsTraining(Date trainingDate) {
		this.vikingsTraining = trainingDate;
	}
	
	public Date getTwinsManagerTraining() {
		return this.twinsManagerTraining;
	}
	
	public void setTwinsManagerTraining(Date trainingDate) {
		this.twinsManagerTraining = trainingDate;
	}
	
	public Date getVikingsManagerTraining() {
		return this.vikingsManagerTraining;
	}
	
	public void setVikingsManagerTraining(Date trainingDate) {
		this.vikingsManagerTraining = trainingDate;
	}
	
	public void setAdministrator(boolean administrator) {
		this.administrator = administrator;
	}
	
	public List<String> getSignedUpEvents() {
		return this.signedUpEvents;
	}
	
	public void setSignedUpEvents(List<String> signedUpEvents) {
		this.signedUpEvents = signedUpEvents;
	}
	
	public void addEvent(VolunteerEvent event) {
		if(this.signedUpEvents == null) {
			this.signedUpEvents = new ArrayList<String>();
		}
		this.signedUpEvents.add(event.getKey());
	}

	public void removeEvent(VolunteerEvent event) {
		if(this.signedUpEvents != null) {
			this.signedUpEvents.remove(event.getKey());
		}
	}
}
